<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<%@page import="java.io.File"%>
<%@page import="securityproject.utils.Constants"%>
<%@page import="securityproject.EditRule"%>
<%@page import="securityproject.utils.RuleUtils"%>
<%@page import="securityproject.PresentRule"%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<title>Code Sharing Web</title>
	<link rel="stylesheet" type="text/css" href="common.css" />
	<link rel="stylesheet" type="text/css" href="ManageRules.css" />
	<script type="text/javascript" src="ManageRules.js"> </script>
</head>
<body>
<img src="img/background.jpg" alt="" id="bg" />

<div id="content">

<div>
	
	<h1>Manage Rules</h1>
	
	<div align="left" style="margin-right: 16px">
		<div>
			<table class ="ruleHeader" style="width: 100%;">
				<thead>
					<tr style="width: 100%;">
						<td style="width: 8%;">Delete</td>
						<td style="width: 8%;">Active</td>
						<td style="width: 50%;">Rule Name</td>
						<td style="width: 17%;">Rule Type</td>
						<td style="width: 17%;">Filter Type</td>
					</tr>	
				</thead>
			</table>
		</div>
	</div>
</div>
<div id="layout">
		<% String ruleScope = request.getParameter(RuleUtils.RULE_SCOPE); %>
		<form method="post" action=<%= "ruleManager/show?"+ RuleUtils.RULE_SCOPE + "=" + ruleScope %> name="manageRules" id="manageRulesForm">
			<div style="height: 300px; overflow: scroll;">
				<table class="ruleDetails" style="width: 100%;">
				<%
					File activeXSLRulesFolder = new File(RuleUtils.getRuleFolder(ruleScope, true));
																
					for (File xslRule : activeXSLRulesFolder.listFiles()) {
						String ruleName = RuleUtils.getRuleName(xslRule.getName());
				%>
		 			<tr style="width: 100%;">
		 				<td  style="width: 8%;">
					 		<input type="checkbox" id="<%=RuleUtils.DELETE_PREFIX + xslRule.getName()%>" name="<%="_to_del"+xslRule.getName()%>" />
					 	</td>
					 	<td  style="width: 8%;">
					 		<input type="checkbox" id="<%=xslRule.getName()%>" name="<%=xslRule.getName()%>"  checked="checked" />
					 	</td>
					 	<td  style="width: 50%;">
					 		<a href=<%="presentRule/show?rule=" + ruleName + "&active=y"%> target="MainWindow"><%= ruleName %></a>
					 	</td>
					 	<td  style="width: 17%;">
					 		<%= RuleUtils.getRuleType(xslRule.getName()) %>
					 	</td>
					 	<td  style="width: 17%;">
					 		<%= RuleUtils.getFilterType(xslRule.getName()) %>
					 	</td>
					</tr>
				 	
				 	
		
				<%
				 	}	

					File inactiveXSLRulesFolder = new File(RuleUtils.getRuleFolder(
										ruleScope, false));
				 														
				 	for (File xslRule : inactiveXSLRulesFolder.listFiles()) {
				 					String ruleName = RuleUtils.getRuleName(xslRule.getName());
				 %>
			 	
			 		<tr style="width: 80%;">
			 			<td style="width: 8%;">
			 				<input type="checkbox" id="<%= RuleUtils.DELETE_PREFIX + xslRule.getName()%>" name="<%="_to_del"+xslRule.getName()%>"/>
				 		</td>
				 		<td style="width: 8%;">
				 			<input type="checkbox" id="<%=xslRule.getName()%>" name="<%=xslRule.getName()%>" style="white-space: pre"/>
				 		</td>
				 		<td style="width: 50%;">
				 			<a href=<%="presentRule/show?rule=" + ruleName + "&active=n"%> target="MainWindow"><%=ruleName%></a>
						</td>
						<td  style="width: 17%;">
					 		<%= RuleUtils.getRuleType(xslRule.getName()) %>
					 	</td>
					 	<td  style="width: 17%;">
					 		<%= RuleUtils.getFilterType(xslRule.getName()) %>
					 	</td>
					</tr>
				<%
					}
				%>			
			</table>
			</div>
			<div>
			<p>
				<input type="submit" id="deleteFiles" name="deleteFiles" value="Delete Selected files"  />
				<input type="submit" value="Save Changes" />
			</p>
			</div>
		</form>	
		
		<form method="post" action=<%="presentRule/show?" + PresentRule.NEW_RULE + "=" + PresentRule.NEW_RULE_VALUE%> name="newRule" id="newRuleForm" >
			<p>
				<input type="submit" value="New Rule" />
			</p>
		
		</form>
		
		
		<form name="fileSpecificRules" id="fileSpecificRules" >
			
			<select>
						<!--<option> Choose</option>-->
				<% 
				// TODO : find out if there is a better way to go to the logs folder
				File filterXSLRulesFolder = new File(Constants.XSL_FILTER_RULES_FOLDER);
			
				for (File fileRulesFolder : filterXSLRulesFolder.listFiles()) {
					
					String ruleFolder = fileRulesFolder.getName();
					
					if (ruleFolder.equals(ruleScope)) {
				%>			
							
						<option onclick=<%="javascript:window.location='ManageRules.jsp?" + RuleUtils.RULE_SCOPE + "=" + ruleFolder + "'" %> selected="selected" ><%=ruleFolder%> </option>
				<%
					} else {
						%>
						<option onclick=<%="javascript:window.location='ManageRules.jsp?" + RuleUtils.RULE_SCOPE + "=" + ruleFolder + "'" %> ><%=ruleFolder%> </option>
						<%
					}
				}
				%>
			</select>				
		</form>
</div>

</div>

</body>
</html>